package com.css.bjdt_report.dataSetManage.service;

import java.util.List;
import java.util.Map;

import org.nutz.dao.Cnd;
import org.nutz.dao.Condition;
import org.nutz.dao.Dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.css.bjdt_report.dataSetManage.entity.DataSet;
import com.css.bjdt_report.util.PageQuerys;

@Service
public class DataSetService {
	@Autowired
	private Dao dao;

	//分页查询
	public Map queryPage(Condition cnd, int pageNum, int pageSize) {
		Map result = PageQuerys.ligerGridQuery(dao, DataSet.class, cnd, pageNum, pageSize);
		List<DataSet> dataSetList = (List<DataSet>) result.get("Rows");
		for (DataSet dataSet : dataSetList) {
			if (dataSet.getTableType() == 1) {
				dataSet.setTypeName("表");
			} else {
				dataSet.setTypeName("视图");
			}
		}
		return result;
	}

	//删除
	public int clear(List<Integer> ids) {
		return dao.clear(DataSet.class, Cnd.where("id", "IN", ids));
	}

	//插入
	public DataSet insert(DataSet record) {
		return dao.insert(record);
	}

	//删除一条信息集
	public void delete(String id) {
		dao.delete(DataSet.class, id);
	}

	//查询单条
	public DataSet fetch(Integer id) {
		return dao.fetch(DataSet.class, id);
	}

	//查询信息集内容
	public DataSet querySetById(String id) {
		return dao.fetch(DataSet.class, id);
	}

	//更新非空
	public int updateIgnoreNull(List<DataSet> records) {
		return dao.updateIgnoreNull(records);
	}

	//更新
	public int update(DataSet record) {
		return dao.update(record);
	}

	//查询
	public List<DataSet> query(Condition cnd) {
		return dao.query(DataSet.class, cnd, null);
	}

	//通过Id获得数据集的名称
	public String getSetNameById(String id) {
		DataSet dataSet = dao.fetch(DataSet.class, id);
		return dataSet.getChineseName();
	}
}
